

import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

import Layout from '@/layout'

import operationRouter from './modules/operation'
import departmentRouter from './modules/department'
import swiperRouter from './modules/swiper'
import userRouter from './modules/user'
import workRouter from './modules/work'
import commentRouter from './modules/comment'
import adviseRouter from './modules/advise'
import postRouter from './modules/post';

import backupsRouter from "./modules/backups";
import messageRouter from "./modules/message";
import maintainRouter from './modules/maintain'
import mobileRouter from './modules/mobile'

export const constantRoutes = [
  // 设置
  operationRouter,
  //人力资源公司
  departmentRouter,
  //零工驿站管理
  postRouter,
  //轮播图
  swiperRouter,
  //用户
  userRouter,
  //零活
  workRouter,
  //评价
  commentRouter,
  //意见反馈
  adviseRouter,

  //数据
  backupsRouter,
  //消息通知
  messageRouter,
  // 维护
  maintainRouter,

  //移动端管理
  mobileRouter,

  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [
      {
        path: '/redirect/:path(.*)',
        component: () => import('@/views/redirect/index')
      }
    ]
  },
  {
    path: '/auth-send',
    component: () => import('@/views/mobile/auth-send'),
    hidden: true
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [
      {
        path: 'dashboard',
        component: () => import('@/views/dashboard/index'),
        name: 'Dashboard',
        meta: { title: '主页', icon: 'dashboard', affix: true }
      },
    ]
  },
  {
    path: '/enter',
    component: () => import('@/views/enter/index'),
    hidden: true
  },
  {
    path: '/setting/uploadPicture',
    component: () => import('@/components/uploadPicture/index.vue'),
    name: 'uploadPicture'
  },
  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
export const asyncRoutes = [

]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  //mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
